<?php
/**
 * Created by PhpStorm.
 * User: 雨寒
 * Date: 2018/7/18
 * Time: 上午1:08
 */
namespace app\admin\controller;

use think\Db;
use \think\Exception;
use app\common\model\Settings;
use app\common\model\Message;

class Index extends Common
{
    public function index()
    {
        $this->templateTitle('首页');
        /*********************订单概况*************************/
        /*获取订单信息*/
        $order=Db::name('order');
        /*总订单*/
        $all_order=$order
            ->field('count(*) as num')
            ->find();
        /*未支付订单*/
        $order0=$order
            ->where("pay_status",0)
            ->field('count(*) as num')
            ->find();
        /*未发货*/
        $order1=$order
            ->where("order_status",1)
            ->field('count(*) as num')
            ->find();
        /*未收货订单*/
        $order2=$order
            ->where("order_status",2)
            ->field('count(*) as num')
            ->find();
        /*已完成*/
        $order3=$order
            ->where("order_status","in", [3,5])
            ->field('count(*) as num')
            ->find();

        /*订单状态*/
        $alldata2=json_encode(array(
            array(
                "label"=>"未付款",
                "value"=>$order0['num'],
            ),
            array(
                "label"=>"未发货",
                "value"=>$order1['num'],
            ),
            array(
                "label"=>"未收货",
                "value"=>$order2['num'],
            ),
            array(
                "label"=>"已完成",
                "value"=>$order3['num']
            ),
        ));
        $this->assign('all_order',$all_order['num']);
        $this->assign('order0',$order0['num']);
        $this->assign('order1',$order1['num']);
        $this->assign('order2',$order2['num']);
        $this->assign('order3',$order3['num']);
        $this->assign('alldata2',$alldata2);


        /****************** 会员状态 ********************/
        $user_total = \db("user")->count();
        $user_check = \db("user")->where("brand_id", "")->count();
        $user_num = \db("user")->where("brand_id", "neq","")->where("in_blacklist", 0)->count();
        $user_black = \db("user")->where("in_blacklist", 1)->count();
        $this->assign("user_total", $user_total);
        $this->assign("user_check", $user_check);
        $this->assign("user_num", $user_num);
        $this->assign("user_black", $user_black);
        $alldata3=json_encode(array(
            array(
                "label"=>"游客",
                "value"=>$user_check,
            ),
            array(
                "label"=>"会员",
                "value"=>$user_num,
            ),
            array(
                "label"=>"黑名单",
                "value"=>$user_black,
            )
        ));
        $this->assign("alldata3",$alldata3);
        /*全局配置*/
        $settings = Settings::getSettings(H_SETTINGS_GLOBAL,2);
        $this->assign('settings',$settings);
        return $this->fetch();
    }
}